﻿// Apache-2.0 License
// Copyright (c) 2021-2022 朱飞龙
// 电话/微信：18706708563  QQ群：136192142

using Microsoft.AspNetCore.Mvc.Formatters;
using Radius.NET.Interface.Kingdee.Attributes;
using Radius.NET.Interface.Kingdee.Entity;
using Radius.NET.Interface.Kingdee.Service.SaModule.XSCK.Dto;
using Radius.NET.Interface.Kingdee.Service.StockWareModule.STK_AssembledApp.Dto;
using static Radius.NET.Interface.Kingdee.Service.Production.KindeeIssueDto;
using FAUXPROPID__FF100001 = Radius.NET.Interface.Kingdee.Service.StockWareModule.STK_AssembledApp.Dto.FAUXPROPID__FF100001;
using FBomID = Radius.NET.Interface.Kingdee.Service.StockWareModule.STK_AssembledApp.Dto.FBomID;
using FOwnerID = Radius.NET.Interface.Kingdee.Service.StockWareModule.STK_AssembledApp.Dto.FOwnerID;
using FStockID = Radius.NET.Interface.Kingdee.Service.StockWareModule.STK_AssembledApp.Dto.FStockID;
using FStockStatusID = Radius.NET.Interface.Kingdee.Service.StockWareModule.STK_AssembledApp.Dto.FStockStatusID;

namespace Radius.NET.Interface.Kingdee.Service.StockWareModule.Dto;
public class KindeeStockWareDto
{

    #region 生成其他出库单JSON
    public static object BuildQtckJsonData(InventoryEvidence evidence)
    {
        var obj = new
        {
            NeedUpDateFields = new List<object>(),
            NeedReturnFields = new List<object>(),
            IsDeleteEntry = true,
            SubSystemId = "",
            IsVerifyBaseDataField = false,
            IsEntryBatchFill = true,
            ValidateFlag = true,
            NumberSearch = true,
            InterationFlags = "",
            Model = new
            {
                FID = 0,
                FBillNo = evidence.Evidence_Number,
                FBillTypeID = new
                {
                    FNUMBER = "QTCKD01_SYS"
                },
                FStockOrgId = new
                {
                    FNumber = KingdeeConfigConst.ORGID
                },
                FPickOrgId = new
                {
                    FNumber = KingdeeConfigConst.ORGID
                },
                FStockDirect = "GENERAL",
                FDate = evidence.Date,
                FCustId = new
                {
                    FNumber = ""
                },
                FDeptId = new
                {
                    FNumber = "BM0010"
                },
                FPickerId = new
                {
                    FStaffNumber = ""
                },
                FStockerId = new
                {
                    FNumber = ""
                },
                FStockerGroupId = new
                {
                    FNumber = ""
                },
                FBizType = "",
                FOwnerTypeIdHead = "BD_OwnerOrg",
                FOwnerIdHead = new
                {
                    FNumber = KingdeeConfigConst.ORGID
                },
                FNote = "",
                FBaseCurrId = new
                {
                    FNumber = "PRE001"
                },
                FScanBox = "",
                F_GDRJ_Base = new
                {
                    FNUMBER = "CKLX0005"
                },
                F_GDRJ_PrintTimes = 0,
                F_GDRJ_PrintDateTime = "",
                F_GDRJ_Base1 = new
                {
                    FSTAFFNUMBER = ""
                },
                F_GDRJ_Base2 = new
                {
                    FSTAFFNUMBER = ""
                },
                F_GDRJ_Text = "",
                F_GDRJ_KH = new
                {
                    FNUMBER = ""
                },
                F_GDRJ_XSZZ = new
                {
                    FNumber = ""
                },
                F_GDRJ_JHDD = new
                {
                    FNUMBER = ""
                },
                F_GDRJ_UserId = new
                {
                    FUserID = ""
                },
                F_GDRJ_Datetime = "",
                FEntity = new List<object>()
            }
        };

        foreach (var item in evidence.FG_InvDetail)
        {

            var child = new
            {
                FEntryID = 0,
                FMaterialId = new
                {
                    FNumber = item.Inventory_ID
                },
                FAuxPropId = new
                {
                    FAUXPROPID__FF100002 = new
                    {
                        FNumber = ""
                    },
                    FAUXPROPID__FF100003 = new
                    {
                        FNumber = ""
                    },
                    FAUXPROPID__FF100004 = new
                    {
                        FNumber = ""
                    }
                },
                FUnitID = new
                {
                    FNumber = item.FG_Inventory is not null ? item.FG_Inventory.Unit : "GE01"
                },
                FQty = item.Actual_Qty,
                FBaseUnitId = new
                {
                    FNumber = item.FG_Inventory is not null ? item.FG_Inventory.Unit : "GE01"
                },
                F_GDRJ_Integer = 0,
                F_GDRJ_Text1 = "",
                FStockId = new
                {
                    FNumber = evidence.Stock_ID
                },
                FStockLocId = new
                {
                    FSTOCKLOCID__FF100002 = new
                    {
                        FNumber = ""
                    },
                    FSTOCKLOCID__FF100006 = new
                    {
                        FNumber = ""
                    },
                    FSTOCKLOCID__FF100008 = new
                    {
                        FNumber = ""
                    },
                    FSTOCKLOCID__FF100010 = new
                    {
                        FNumber = item.Stk_ID
                    },
                    FSTOCKLOCID__FF100011 = new
                    {
                        FNumber = ""
                    },
                    FSTOCKLOCID__FF100012 = new
                    {
                        FNumber = ""
                    },
                    FSTOCKLOCID__FF100013 = new
                    {
                        FNumber = ""
                    },
                    FSTOCKLOCID__FF100014 = new
                    {
                        FNumber = ""
                    },
                    FSTOCKLOCID__FF100015 = new
                    {
                        FNumber = ""
                    }
                },
                FLot = new
                {
                    FNumber = ""
                },
                FOwnerTypeId = "BD_OwnerOrg",
                FPRODUCTGROUPID = new
                {
                    FNUMBER = ""
                },
                FOwnerId = new
                {
                    FNumber = KingdeeConfigConst.ORGID
                },
                FBomId = new
                {
                    FNumber = ""
                },
                FEntryNote = "",
                FProjectNo = "",
                FProduceDate = "",
                FServiceContext = "",
                FStockStatusId = new
                {
                    FNumber = "KCZT01_SYS"
                },
                FMtoNo = "",
                FCostItem = new
                {
                    FNUMBER = ""
                },
                FKeeperTypeId = "BD_KeeperOrg",
                FDistribution = false,
                FKeeperId = new
                {
                    FNumber = KingdeeConfigConst.ORGID
                },
                FExtAuxUnitId = new
                {
                    FNumber = "Tong"
                },
                FExtAuxUnitQty = 0,
                FFMATERIALID = new
                {
                    FNUMBER = ""
                },
                F_GDRJ_Lot = new
                {
                    FNumber = ""
                },
                F_GDRJ_Amount = 0,
                FSerialSubEntity = new List<object>()
                {
                    new{
                     FDetailID = 0,
                        FSerialNo = "",
                        FSerialNote = ""
                    }
                }
            };
            obj.Model.FEntity.Add(child);
        }

        return obj;
    }
    #endregion

    #region 生成生产领料单保存JSON
    public static object BuildSclldJsonData(InventoryEvidence item)
    {
        Entity.PRD_PickMtrl obj = new()
        {
            Model = new ()
            {
                FID = 0,
                FBillNo = "",//单据编号
                FBillType = new()
                {  //单据类型
                    FNumber = "SCLLD01_SYS"
                },
                FDate = item.Date, //日期
                FStockOrgId = new()
                {  //发料组织
                    FNumber = KingdeeConfigConst.ORGID
                },
                FStockId0 = new()
                {  //仓库
                    FNumber = ""
                },
                FPrdOrgId = new()
                {   //生产组织
                    FNumber = KingdeeConfigConst.ORGID
                },
                FWorkShopId = new()
                {   //生产车间
                    FNumber = ""
                },
                FOwnerTypeId0 = "BD_OwnerOrg",  //货主类型
                FOwnerId0 = new()
                {    //货主
                    FNumber = ""
                },
                FPickerId = new() { },   //领料人
                FSTOCKERID = new()
                {   //仓管员
                    FNAME = ""
                },
                FDescription = "",  //备注
                FCurrId = new()
                {   //本位币
                    FNumber = ""
                },
                FIsCrossTrade = "false",
                FVmiBusiness = "false",
                FScanBox = "",
                FSourceType = "",
                FIsOwnerTInclOrg = "false",
                FEntity = new()
            }
        };
        foreach (var e in item.FG_InvDetail)
        {
            Entity.PRD_PickMtrl.FEntityItem fEntityItem = new()
            {
                FEntryID = 0,
                FParentMaterialId = new()
                {  //产品编码
                    FNumber = ""
                },
                FBaseStockActualQty = e.Qty,  //主库存基本单位实发数量
                FConsome = "",   //消耗汇总
                FFPMBillNo = "",// 生产备料单据编号
                FReserveType = "",  //预留类型
                FMaterialId = new ()
                {  //物料编码
                    FNumber = e.Inventory_ID
                },
                FEntryWorkShopId = new()
                {
                    FNumber = ""
                },
                FUnitID = new ()
                {   //单位 需要赋值
                    FNumber = e.FG_Inventory is not null ? e.FG_Inventory.Unit : "GONGJIN01"
                },
                FBaseUnitId = new ()
                {   //基本单位 需要赋值
                    FNumber = e.FG_Inventory is not null ? e.FG_Inventory.Unit : "GONGJIN01"
                },
                FStockUnitId = new ()
                {   //主库存单位 需要赋值
                    FNumber = e.FG_Inventory is not null ? e.FG_Inventory.Unit : "GONGJIN01"
                },

                FAppQty = e.Qty,  //申请数量
                FActualQty = e.Qty, //实发数量
                FBaseActualQty = e.Qty, //基本单位实发数量
                FEntryVmiBusiness = "false",
                FOptPlanBillNo = "",  //工序计划单编号
                FStockId = new ()
                {  //仓库
                    FNumber = item.Stock_ID
                },
                FStockLocId = new ()
                {
                    FNumber = ""
                }, //仓位
                FLot = new ()
                {
                    FNumber = e.ProjectBatch

                },
                FCobyBomEntryID = 0,
                FProcessId = new ()
                {  //作业
                    FNumber = ""
                },
                FPPBomBillNo = "",  //投料单的单据编号
                FGroupRow = "",
                FSrcPickEntryId = 0,
                FSrcBusinessType = "",   //业务来源类型
                FQueryStockUpdate = "",
                FProduceDate = "",  //生产日期
                FMoBillNo = "",  //生产订单编号  工程单下划线前面的
                FMoEntryId = 0,     //生产订单的分录ID
                FMoId = 0,//生产订单的主键ID
                FPPBomEntryId = "",   //投料单的分录ID
                FMoEntrySeq = "",        //生产订单的分录行号  工程单下划线后面的
                FSrcBillType = "",  //原单单据类型  写死的
                FSrcBillNo = "",  //原单单据编号  投料单的单据单号
                FEntrySrcInterId = "",    //投料单的主键ID
                FEntrySrcEnteryId = "",    //投料单的分录ID
                FEntrySrcEntrySeq = 0,        //投料单的分录行号
                FParentOwnerTypeId = "BD_OwnerOrg",
                FParentOwnerId = new ()
                {
                    FNumber = KingdeeConfigConst.ORGID
                },
                FKeeperTypeId = "BD_KeeperOrg",
                FKeeperId = new ()
                {
                    FNumber = KingdeeConfigConst.ORGID
                },
                FOwnerId = new ()
                {
                    FNumber = KingdeeConfigConst.ORGID
                },
                FEntity_Link = new() {
                       new (){
                            FEntity_Link_FFlowId= "",
                            FEntity_Link_FFlowLineId= 0,
                            FEntity_Link_FRuleId= "",
                            FEntity_Link_FSTableName= "",
                            FEntity_Link_FSBillId= "",
                            FEntity_Link_FSId= "",
                            FEntity_Link_FBaseActualQtyOld= 0,//原始携带量   ---生产领料单的实发数量
                            FEntity_Link_FBaseActualQty= 0 //修改携带量   ---生产领料单的实发数量
                       }
                    }
            };
            obj.Model.FEntity.Add(fEntityItem);
        }

        return obj;
    }
    #endregion

    #region 组装拆卸单保存JSON
    /// <summary>
    /// 生成组装拆卸单JSON
    /// </summary>
    /// <param name="item"></param>
    /// <returns></returns>
    public static object BuildzzcxdJsonData(InventoryEvidence item)
    {
        var childDataQ = item.FG_InvDetail.Where((row) => row.Vol == 9).ToList();
        STK_AssembledApp.Dto.STK_AssembledApp obj = new()
        {
            NeedUpDateFields = new List<string>(),
            NeedReturnFields = new List<string>(),
            IsDeleteEntry = "true",
            SubSystemId = "",
            IsVerifyBaseDataField = "false",
            IsEntryBatchFill = "true",
            ValidateFlag = "true",
            NumberSearch = "true",
            InterationFlags = "",
            Model = new STK_AssembledApp.Dto.Model()
            {
                FID = 0,
                FBillTypeID = new STK_AssembledApp.Dto.FBillTypeID()
                {
                    FNUMBER = "ZZCX01_SYS"
                },
                FStockOrgId = new()
                {
                    FNumber = KingdeeConfigConst.ORGID //库存组织
                },
                FAffairType = "Assembly", //事务类型 （必填）
                FDate = item.Date?.ToString("yyyy-MM-dd"),
                FDeptID = new STK_AssembledApp.Dto.FDeptID()
                { //部门
                    FNumber = ""
                },
                FSTOCKERID = new STK_AssembledApp.Dto.FSTOCKERID()
                { //仓管员
                    FNumber = ""
                },
                FSTOCKERGROUPID = new STK_AssembledApp.Dto.FSTOCKERGROUPID()
                {//库存组
                    FNumber = ""
                },
                FNote = "", //备注
                FOwnerTypeIdHead = "BD_OwnerOrg", //成品货主类型 必填
                FOwnerIdHead = new STK_AssembledApp.Dto.FOwnerIdHead()
                { //成品货主 必填
                    FNumber = KingdeeConfigConst.ORGID
                },
                FSubProOwnTypeIdH = "BD_OwnerOrg",  //子件货主类型  必填
                FSubProOwnerIdH = new STK_AssembledApp.Dto.FSubProOwnerIdH()
                { //子件货主 必填
                    FNumber = KingdeeConfigConst.ORGID
                },
                FScanBox = "",
                FScanBoxSenty = "",
                FEntity = new List<STK_AssembledApp.Dto.FEntityItem>(),
            }
        };
        //拆装前的数据
        obj.Model.FEntity.Add(new STK_AssembledApp.Dto.FEntityItem()
        {
            FEntryID = 0,
            FMaterialID = new STK_AssembledApp.Dto.FMaterialID()
            { //物料编码
                FNumber = childDataQ[0].Inventory_ID
            },
            FAuxPropId = new STK_AssembledApp.Dto.FAuxPropId()
            {
                FAUXPROPID__FF100001 = new FAUXPROPID__FF100001
                {
                    FNumber = ""
                },
                FAUXPROPID__FF100002 = new FAUXPROPID__FF100002
                {
                    FNumber = childDataQ[0].PackID
                }
            },
            FUnitID = new FUnitID()
            { //单位
                FNumber = childDataQ[0].FG_Inventory is not null ? childDataQ[0].FG_Inventory.Unit : "kg"
            },
            FQty = childDataQ[0].Actual_Qty,

            FStockID = new FStockID()
            { //仓库 必填
                FNumber = item.Stock_ID
            },
            FStockLocId = new () { }, //仓位
            FStockStatusID = new FStockStatusID()
            { //库存状态必填
                FNumber = "KCZT01_SYS"
            },
            FLOT = new FLOT()
            { //批号
                FNumber = childDataQ[0].ProjectBatch
            },
            FBaseUnitID = new FBaseUnitID()
            {//基本单位 必填
                FNumber = childDataQ[0].FG_Inventory is not null ? childDataQ[0].FG_Inventory.Unit : "kg"
            },
            Fee_ETY = 0, //费用
            FRefBomID = new FRefBomID
            { //参照BOM版本
                FNumber = ""
            },
            FDescription = "", //备注
            FMTONO = "", //计划跟踪号
            FProjectNo = "", //项目编号
            FOwnerTypeID = "BD_OwnerOrg", //货主类型(必填)
            FOwnerID = new FOwnerID()
            { //货主 必填
                FNumber = KingdeeConfigConst.ORGID
            },
            FKeeperTypeID = "BD_KeeperOrg", //保管者类型
            FExtAuxUnitId = new FExtAuxUnitId()
            { //辅单位
                FNumber = "Tong"
            },
            FKeeperID = new FKeeperID()
            { //保管者
                FNumber = KingdeeConfigConst.ORGID
            },
            FExtAuxUnitQty = childDataQ[0].Actual_Qty, //数量
            FBomID = new FBomID()
            { //BOM版本
                FNumber = ""
            },
            FProduceDate = childDataQ[0].MakeBeginDate?.ToString("yyyy-MM-dd"),
            FEXPIRYDATE = childDataQ[0].EndDate?.ToString("yyyy-MM-dd"),
            FSubEntity = new List<FSubEntityItem>(),//子件表,
            FSerialEntity = new List<FSerialEntityItem>() {
                new FSerialEntityItem()
                {
                    FDetailID=0,
                    FSerialNo= "",
                    FSerialNote= ""
                }
            }
        });
        foreach (var el in item.FG_InvDetail)
        {
            if (el.Vol == 8)
            {
                obj.Model.FEntity[0].FSubEntity.Add(new FSubEntityItem()
                {
                    FDetailID = 0,
                    FMaterialIDSETY = new FMaterialIDSETY()
                    { //物料编码
                        FNumber = el.Inventory_ID
                    },
                    FAuxPropIdSETY = new FAuxPropIdSETY
                    {
                        FAUXPROPIDSETY__FF100001 = new FAUXPROPIDSETY__FF100001
                        {
                            FNumber = ""
                        },
                        FAUXPROPIDSETY__FF100002 = new FAUXPROPIDSETY__FF100002
                        {
                            FNumber = el.PackID
                        }
                    },
                    FUnitIDSETY = new FUnitIDSETY()
                    { //单位 必填
                        FNumber = el.FG_Inventory is not null ? el.FG_Inventory.Unit : "kg"
                    },
                    FQtySETY = el.Actual_Qty,
                    FStockIDSETY = new FStockIDSETY()
                    { //仓库 必填
                        FNumber = item.Stock_ID
                    },
                    FStockLocIdSETY = new FStockLocIdSETY() { }, //仓位
                    FStockStatusIDSETY = new FStockStatusIDSETY()
                    { //库存状态
                        FNumber = "KCZT01_SYS"
                    },
                    FLOTSETY = new FLOTSETY()
                    { //批号
                        FNumber = el.ProjectBatch
                    },
                    FCostProportion = 0, //成本拆分比例
                    FBaseUnitIDSETY = new FBaseUnitIDSETY()
                    { //基本单位
                        FNumber = el.FG_Inventory is not null ? el.FG_Inventory.Unit : "kg"
                    },
                    FDescriptionSETY = "", //备注
                    FKeeperTypeIDSETY = "BD_KeeperOrg", //保管者类型 必填
                    FKeeperIDSETY = new FKeeperIDSETY()
                    { //保管者 必填
                        FNumber = KingdeeConfigConst.ORGID
                    },
                    FMTONOSETY = "", //计划跟踪号
                    FProjectNoSETY = "", //项目编号
                    FOwnerTypeIDSETY = "BD_OwnerOrg", //货主类型
                    FOwnerIDSETY = new()
                    {
                        FNumber = KingdeeConfigConst.ORGID//货主
                    },
                    FProduceDateSETY = el.MakeBeginDate?.ToString("yyyy-MM-dd"), //生产日期
                    FExtAuxUnitIdSETY = new()
                    { //单位
                        FNumber = "Tong"
                    },
                    FEXPIRYDATESETY = el.EndDate?.ToString("yyyy-MM-dd"), //有效期至
                    FExtAuxUnitQtySETY = el.NPKG, //数量
                    FBomIDSETY = new FBomIDSETY()
                    {
                        FNumber = "" //bom版本
                    },
                    FSubSerialEntity = new(){
                         new ()
                         {
                             FSNDetailID=0,
                             FSerialNoSety="",
                             FSerialNoteSety=""
                         }
                     }
                });
            }
        }

        return obj;
    }
    #endregion

    #region 销售出库单保存JSON
    /// <summary>
    /// 销售出库单保存JSON
    /// </summary>
    /// <param name="item"></param>
    /// <param name="sAL_DELIVERYNOTICEDtos"></param>
    /// <param name="materials"></param>
    /// <returns></returns>
    public static object BuildxsckdJsonData(InventoryEvidence item, List<SAL_DELIVERYNOTICE_Dto> sAL_DELIVERYNOTICEDtos, Dictionary<string, BD_MATERIAL_Dto> materials)
    {
        SAL_OUTSTOCK obj = new()
        {
            NeedUpDateFields = new List<string>(),
            NeedReturnFields = new List<string>(),
            IsDeleteEntry = "true",
            SubSystemId = "",
            IsVerifyBaseDataField = "false",
            IsEntryBatchFill = "true",
            ValidateFlag = "true",
            NumberSearch = "true",
            InterationFlags = "",
            Model = new()
            {
                FBillTypeID = new()
                {
                    FNUMBER = "XSCKD01_SYS"
                },
                FBillNo = "",
                FDate = item.Date?.ToString("yyyy-MM-dd"),
                FSaleOrgId = new()
                {
                    FNumber = KingdeeConfigConst.ORGID
                },
                FCustomerID = new()
                {
                    FNumber = item.ContactNum
                },
                FSaleDeptID = new()
                {
                    FNumber = sAL_DELIVERYNOTICEDtos.FirstOrDefault().FSaleDeptID_FNumber
                },
                FHeadLocationId = new()
                {
                    FNumber = ""
                },
                FCorrespondOrgId = new()
                {
                    FNumber = ""
                },
                FCarrierID = new()
                {
                    FNumber = ""
                },
                FCarriageNO = "",
                FSalesGroupID = new()
                {
                    FNumber = ""
                },
                FSalesManID = new()
                {
                    FNumber = sAL_DELIVERYNOTICEDtos.FirstOrDefault().FSalesManID_FNumber
                },
                FStockOrgId = new()
                {
                    FNumber = KingdeeConfigConst.ORGID
                },
                FDeliveryDeptID = new()
                {
                    FNumber = ""
                },
                FLinkMan = "",
                FLinkPhone = "",
                FStockerGroupID = new()
                {
                    FNumber = ""
                },
                FStockerID = new()
                {
                    FNumber = ""
                },
                FNote = "",
                FReceiverID = new()
                {
                    FNumber = sAL_DELIVERYNOTICEDtos.FirstOrDefault().FReceiverID_FNumber
                },
                FReceiveAddress = "",
                FSettleID = new()
                {
                    FNumber = sAL_DELIVERYNOTICEDtos.FirstOrDefault().FSettleID_FNumber
                },
                FReceiverContactID = new()
                {
                    FNAME = ""
                },
                FPayerID = new()
                {
                    FNumber = sAL_DELIVERYNOTICEDtos.FirstOrDefault().FSettleID_FNumber
                },
                FOwnerTypeIdHead = "BD_OwnerOrg",
                FOwnerIdHead = new()
                {
                    FNumber = KingdeeConfigConst.ORGID
                },
                FScanBox = "",
                FCDateOffsetUnit = "",
                FCDateOffsetValue = 0,
                FPlanRecAddress = "",
                FIsTotalServiceOrCost = "false",
                FSHOPNUMBER = "",
                FGYDATE = "",
                FSALECHANNEL = "",
                F_asdg_Assistant1 = new()
                {
                    FNumber = ""
                },
                F_asdg_Text1 = "",
                F_asdg_Assistant2 = new()
                {
                    FNumber = ""
                },
                F_asdg_Text11 = "",
                F_asdg_Text12 = "",
                F_asdg_Text2 = "",
                FEntity = new List<Interface.Kingdee.Service.SaModule.XSCK.Dto.FEntityItem>(),
            }
        };

        foreach (var el in item.FG_InvDetail)
        {
            var sAL_DELIVERYNOTICE = sAL_DELIVERYNOTICEDtos.Find(x => x.FMaterialFNumber == el.Inventory_ID);
            obj.Model.FEntity.Add(new Interface.Kingdee.Service.SaModule.XSCK.Dto.FEntityItem()
            {

                FENTRYID = 0,
                FRowType = "Standard",
                FCustMatID = new FCustMatID()
                {
                    FNumber = ""
                },
                FMaterialID = new Interface.Kingdee.Service.SaModule.XSCK.Dto.FMaterialID()
                {
                    FNumber = el.Inventory_ID
                },
                FAuxPropId = new Interface.Kingdee.Service.SaModule.XSCK.Dto.FAuxPropId()
                {
                    FAUXPROPID__FF100002 = new Interface.Kingdee.Service.SaModule.XSCK.Dto.FAUXPROPID__FF100002()
                    {
                        FNumber = el.PackID
                    },
                    FAUXPROPID__FF100001 = new Interface.Kingdee.Service.SaModule.XSCK.Dto.FAUXPROPID__FF100001()
                    {
                        FNumber = ""
                    }
                },
                FUnitID = new Interface.Kingdee.Service.SaModule.XSCK.Dto.FUnitID()
                {
                    FNumber = string.IsNullOrEmpty(el.FG_Inventory.Unit) ? "kg" : el.FG_Inventory.Unit
                },
                FInventoryQty = 0,
                FParentMatId = new SaModule.XSCK.Dto.FParentMatId()
                {
                    FNUMBER = ""
                },
                FRealQty = el.Actual_Qty,
                FMustQty = el.Actual_Qty,
                FExtAuxUnitQty = 0,
                FDisPriceQty = 0,
                FLot = new Interface.Kingdee.Service.SaModule.XSCK.Dto.FLot()
                {
                    FNumber = el.ProjectBatch
                },
                FPrice = el.Standard_cost,
                FTaxPrice = el.Standard_cost,
                FIsFree = "false",
                FSrcBillNo = item.ReasonID,
                FSoorDerno = sAL_DELIVERYNOTICE.FSrcBillNo,
                FBomID = new Interface.Kingdee.Service.SaModule.XSCK.Dto.FBomID()
                {
                    FNumber = ""
                },
                FOwnerTypeID = "BD_OwnerOrg",
                FOwnerID = new Interface.Kingdee.Service.SaModule.XSCK.Dto.FOwnerID()
                {
                    FNumber = KingdeeConfigConst.ORGID
                },
                F_asdg_Decimal = 0,
                FProduceDate = el.MakeBeginDate?.ToString("yyyy-MM-dd"),
                FExpiryDate = el.EndDate?.ToString("yyyy-MM-dd"),
                FTaxCombination = new SaModule.XSCK.Dto.FTaxCombination()
                {
                    FNumber = ""
                },
                FEntryTaxRate = sAL_DELIVERYNOTICE.FEntryTaxRate,
                FAuxUnitQty = el.NPKG,
                FExtAuxUnitId = new Interface.Kingdee.Service.SaModule.XSCK.Dto.FExtAuxUnitId()
                {
                    FNumber = materials.ContainsKey(el.Inventory_ID) ? materials[el.Inventory_ID].FAuxUnitID__FNumber : "Tong"
                },
                FStockID = new Interface.Kingdee.Service.SaModule.XSCK.Dto.FStockID()
                {
                    FNumber = item.Stock_ID.ToString()
                },
                FStockLocID = new FStockLocID() { },
                FStockStatusID = new Interface.Kingdee.Service.SaModule.XSCK.Dto.FStockStatusID()
                {
                    FNumber = "KCZT01_SYS"
                },
                FQualifyType = "",
                FMtoNo = "",
                FEntrynote = "",
                FDiscountRate = 0,
                FPriceDiscount = 0,
                FActQty = 0,
                FSalUnitID = new FSalUnitID()
                {
                    FNumber = string.IsNullOrEmpty(el.FG_Inventory.Unit) ? "kg" : el.FG_Inventory.Unit
                },
                FSALUNITQTY = el.Actual_Qty,
                FSALBASEQTY = el.Actual_Qty,
                FPRICEBASEQTY = el.Actual_Qty,
                FProjectNo = "",
                FOUTCONTROL = "false",
                FRepairQty = 0,
                FIsCreateProDoc = "",
                FEOwnerSupplierId = new FEOwnerSupplierId()
                {
                    FNUMBER = ""
                },
                FIsOverLegalOrg = "false",
                FESettleCustomerId = new FESettleCustomerId()
                {
                    FNUMBER = ""
                },
                FPriceListEntry = new SaModule.XSCK.Dto.FPriceListEntry()
                {
                    FNUMBER = ""
                },
                FARNOTJOINQTY = 0,
                FQmEntryID = 0,
                FConvertEntryID = 0,
                FSOEntryId = 0,
                FBeforeDisPriceQty = 0,
                FThirdEntryId = "",
                FSignQty = 0,
                FCheckDelivery = "false",
                FETHIRDBILLNO = "",
                FETHIRDBILLID = "",
                F_asdg_Text = sAL_DELIVERYNOTICE.F_asdg_Text1,
                F_asdg_Assistant = new F_asdg_Assistant()
                {
                    FNumber = ""
                },
                FTaxDetailSubEntity = new List<FTaxDetailSubEntityItem>() {
                    new FTaxDetailSubEntityItem(){
                        FDetailID= 0,
                        FTaxRate= 0
                    }
                },
                FSerialSubEntity = new List<Interface.Kingdee.Service.SaModule.XSCK.Dto.FSerialSubEntityItem>()
                {
                    new Interface.Kingdee.Service.SaModule.XSCK.Dto.FSerialSubEntityItem()
                    {
                        FDetailID= 0,
                        FSerialNo= "",
                        FSerialNote= ""
                    }
                },
                FSrcType= "SAL_DELIVERYNOTICE",
                
                FEntity_Link = new List<Interface.Kingdee.Service.Production.Dto.Qtckd.FEntity_Link>()
                {
                    new Interface.Kingdee.Service.Production.Dto.Qtckd.FEntity_Link()
                    {
                        FEntity_Link_FRuleId="DeliveryNotice-OutStock",
                        FEntity_Link_FSTableName="T_SAL_DELIVERYNOTICEENTRY",
                        FEntity_Link_FSBillId = sAL_DELIVERYNOTICE is null ? "0" : sAL_DELIVERYNOTICE.FID.ToString(),
                        FEntity_Link_FSId = sAL_DELIVERYNOTICE is null ? "0" : sAL_DELIVERYNOTICE.FEntryId.ToString(),
                        FEntity_Link_FBaseUnitQtyOld = el.Actual_Qty,
                        FEntity_Link_FBaseUnitQty=el.Actual_Qty,
                        FEntity_Link_FSALBASEQTYOld = el.Actual_Qty,
                        FEntity_Link_FSALBASEQTY = el.Actual_Qty,
                        FEntity_Link_FAuxUnitQty = el.NPKG,
                    }
                }

            });
        }
        return obj;
    }
    #endregion

}
